//获取中文字符
const getGbkNum = (str: string) => {
  let reg = /[\u4e00-\u9fa5]/g;
  let result = str.match(reg);
  return !result ? 0 : result.length;
}

//获取英文单词/公式个数
// @ts-ignore
const getEnNum = (str: string) => {
  let reg = /[a-z]/gi;
  let result = str.match(reg);
  return !result ? 0 : result.length;
}

//获取英文字符个数
const getEnWordNum = (str: string) => {
  let reg = /[A-Za-z0-9_±/.()%=+-]+/gi;
  let result = str.match(reg);
  return !result ? 0 : result.length;
}

//获取空格个数
// @ts-ignore
const getNullNum = (str: string, c) => {
  let regex = new RegExp(c, "g");
  let result = str.match(regex);
  return !result ? 0 : result.length;
}

//获取标点符号
const getPunctuationNum = (str: string) => {
  let reg =
    /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g;
  let result = str.match(reg);
  return !result ? 0 : result.length;
}

export const delHtmlTag = (str: string) => {
  return str.replace(/<[^>]+>/g,"");  //正则去掉所有的html标记
}

/**
 * 字数统计(Word规则)
 * @returns {*}
 * @param text
 */
export const wordsNum = (text: string) => {
  if (text) {
    return getGbkNum(text) + getEnWordNum(text) + getPunctuationNum(text);
  }
  return 0;
}

export const richWordsNum = (text: string) => {
  if (text) {
    return wordsNum(delHtmlTag(text));
  }
  return 0;
}
